using System.Collections;
using System.Collections.Generic;

namespace ByteFarm.ImageMetaData.Format
{
    public abstract class DirectoryEntry<TTag, TFieldType> : IEnumerable
    {
        protected DirectoryEntry(ushort tagCode, ushort fieldTypeCode, int count)
        {
            TagCode = tagCode;
            FieldTypeCode = fieldTypeCode;
            ValueCount = count;
        }

        public ushort TagCode { get; protected set; }

        public TTag Tag
        {
            get { return (TTag) (object) TagCode; //eeek don't look :( 
            }
        }

        public ushort FieldTypeCode { get; protected set; }

        public TFieldType FieldType
        {
            get { return (TFieldType) (object) FieldTypeCode; //eeek don't look :(
            }
        }

        public int ValueCount { get; protected set; }

        #region IEnumerable Members

        public abstract IEnumerator GetEnumerator();

        #endregion
    }

    public class DirectoryEntry<TTag, TFieldType, TValueType>
        : DirectoryEntry<TTag, TFieldType>
    {
        public DirectoryEntry(ushort tag, ushort fieldType, int count, ICollection<TValueType> values)
            : base(tag, fieldType, count)
        {
            Values = values;
        }

        public ICollection<TValueType> Values { get; protected set; }

        public override IEnumerator GetEnumerator()
        {
            return Values.GetEnumerator();
        }
    }
}